import Vue from 'vue'
import Router from 'vue-router'
import { Four0Four } from '@daelui/vdog/dist/business'
import config from '@/micros/config'

Vue.use(Router)

// 判断环境是否是微应用打开
let microPath = ''
if (window.__POWERED_BY_QIANKUN__) {
  microPath = config.microPath
}

const routes = [
  {
    path: microPath + '/',
    name: 'index',
    component: () => import(/* webpackChunkName: "home" */ '@/views/index'),
    redirect: () => {
      return microPath + '/home'
    },
    children: [
      // 首页
      {
        path: 'home',
        name: 'home',
        component: () => import(/* webpackChunkName: "home" */ '@/views/index/index')
      },
      // 笔记
      {
        path: 'user',
        name: 'user',
        component: () => import(/* webpackChunkName: "user" */ '@/views/user/index'),
        redirect: () => {
          return microPath + '/user/list'
        },
        children: [
          {
            path: 'list',
            name: 'user-list',
            component: () => import(/* webpackChunkName: "user" */ '@/views/user/list')
          },
          {
            path: 'item/:id?',
            name: 'user-item',
            component: () => import(/* webpackChunkName: "user" */ '@/views/user/item')
          },
          {
            path: 'edit/:id?',
            name: 'user-edit',
            component: () => import(/* webpackChunkName: "user" */ '@/views/user/edit')
          },
          {
            path: 'type/list',
            name: 'user-type-list',
            component: () => import(/* webpackChunkName: "user" */ '@/views/user/type/list')
          },
          {
            path: 'type/edit/:id?',
            name: 'user-type-edit',
            component: () => import(/* webpackChunkName: "user" */ '@/views/user/type/edit')
          }
        ]
      }
    ]
  },
  {
    path: microPath + '/404',
    name: '404',
    component: Four0Four,
    props: { home: '/home' }
  }
]

const router = new Router({ routes })

export default router
